//
//  CZStatusTool.m
//  OCKSFWeibo
//
//  Created by 盛 发 况 on 16/4/27.
//  Copyright © 2016年 盛 发 况. All rights reserved.
//

#import "CZStatusTool.h"
#import "CZStatusParam.h"
#import "CZAccountTool.h"
#import "CZAccount.h"
#import "CZHttpTool.h"
#import <MJExtension.h>
#import "CZStatusResult.h"

@implementation CZStatusTool
/**
 *  请求更新的微博数据
 sinceId：返回比这个更大的微博数据
 */
+ (void)newStatusWithSinceId:(NSString *)sinceId success:(void(^)(NSArray *statuses))success failure:(void(^)(NSError *error))failure {

    CZStatusParam *param = [[CZStatusParam alloc] init];
    param.access_token = [CZAccountTool account].access_token;
    if (sinceId) { // 有微博数据，才需要下拉刷新
        param.since_id = sinceId;
    }
    
    [CZHttpTool GET:@"https://api.weibo.com/2/statuses/friends_timeline.json" parameters:param.mj_keyValues success:^(id responseObject) {
        
        CZStatusResult *result = [CZStatusResult mj_objectWithKeyValues:responseObject];
        if (success) {
            success(result.statuses);
        }
        
    } failure:^(NSError *error) {
        
        if (failure) {
            failure(error);
        }
    }];
}


/**
 *  请求更多的微博数据
 *  @param maxId   返回小于等于这个id的微博数据
 */
+ (void)moreStatusWithMaxId:(NSString *)maxId success:(void(^)(NSArray *statuses))success failure:(void(^)(NSError *error))failure {
    
    CZStatusParam *param = [[CZStatusParam alloc] init];
    param.access_token = [CZAccountTool account].access_token;
    if (maxId) { // 有微博数据，才需要下拉刷新
        param.max_id = maxId;
    }
    
    [CZHttpTool GET:@"https://api.weibo.com/2/statuses/friends_timeline.json" parameters:param.mj_keyValues success:^(id responseObject) {
        
        CZStatusResult *result = [CZStatusResult mj_objectWithKeyValues:responseObject];
        if (success) {
            success(result.statuses);
        }
        
    } failure:^(NSError *error) {
        
        if (failure) {
            failure(error);
        }
    }];
    
}

@end



